from appium import webdriver
from appium.webdriver.extensions.android.nativekey import AndroidKey

station_name = '北京西'

desired_caps = {
  'platformName': 'Android', # 被测手机是安卓
  'platformVersion': '7', # 手机安卓版本
  'deviceName': 'xxx', # 设备名，安卓手机可以随意填写
  'appPackage': 'smskb.com', # 启动APP Package名称
  'appActivity': '.activity.launcher.ActivityLauncher', # 启动Activity名称
  'unicodeKeyboard': True, # 使用自带输入法，输入中文时填True
  'resetKeyboard': True, # 执行完程序恢复原来输入法
  'noReset': True,       # 不要重置App
  'newCommandTimeout': 6000,
  'automationName' : 'UiAutomator2'
  # 'app': r'd:\apk\bili.apk',
}

# 连接Appium Server，初始化自动化环境
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 设置缺省等待时间
driver.implicitly_wait(5)

# print(driver.find_element_by_id("mskb.com:id/btn_filter_zzcx"))
# # 点击- 车次车站
driver.find_element_by_id("smskb.com:id/tv_f_cccx").click()

# # 点击 - 车站
driver.find_element_by_id("smskb.com:id/btn_cz").click()

# # 点击 - 搜索框
driver.find_element_by_id("smskb.com:id/ed_cc").click()

driver.keyevent(112) # 按删除键

search_box = driver.find_element_by_id("smskb.com:id/ed_cc")
# # driver.keyevent(30)
# # driver.keyevent(38)
# # driver.keyevent(52)
# # 输入文字
search_box.send_keys(station_name)

# # 点击搜索 "	
driver.find_element_by_id("smskb.com:id/btn_cccx").click()
# 设置缺省等待时间
driver.implicitly_wait(5)
eve = driver.find_elements_by_class_name("android.widget.LinearLayout")
for e in eve: 
  print(e.text)

# driver.find_elements_by_class_name("android.widget.Button")[0].click()


# driver.find_element_by_id("smskb.com:id/dlg_filter_OnlyDC").click()
# driver.find_element_by_id("smskb.com:id/btn_ok").click()



